var ajaxResponse={
	
	callbackErrorFunc: null,
	
	query : function (url_query, data, method){
		if(method==undefined || (method != 'POST' && method != 'post'))method = 'GET';
		
		if(data==undefined)data=null;
		
		$.ajax({
		  url: url_query,
		  type: method,
		  dataType: "json",
		  data: data,
		  context: document.body,
		  success: function($response){
		  	
		  	if($response == null)return null;
		  	
		  	if($response['callbackFunc']!=undefined){
		  		if($response['callbackFunc'] instanceof Object){
		  			
		  			var prop;
		  			var func;
		  			
		  			for (prop in $response['callbackFunc']){
		  			
		  				for (funcName in $response['callbackFunc'][prop]){
		  					
		  					var objCall = funcName.split('.');
		  					
		  					if(objCall.length > 1){
		  						var funcToCall;
		  						var tt;

		  						var rExp = /^(\S+)\s*\((.*)\)$/i;  
		  						var checkJquery = rExp.exec(objCall[0]);
		  						
		  						if(checkJquery != null){
		  							
		  							var funcToCall=window[checkJquery[1]];
		  							
		  							if(funcToCall != undefined){
										var m = 0;
		  								checkJquery[2]=checkJquery[2].replace(/["']+/g, ''); //"
		  								
		  								funcToCall=window[checkJquery[1]](checkJquery[2]);		  								
				  						var methodCall = objCall[1];
		  							}
		  							
		  						}
		  						else{
		  							var funcToCall=window;
		  							for (tt in objCall){
			  							funcToCall=funcToCall[objCall[tt]];
			  						}
		  						}
		  						
		  					}
		  					else{
		  						var funcToCall=window[funcName];
		  					}
		  					
		  					if(funcToCall != undefined){
		  						
		  						var $vars = ajaxResponse.resetObjKeys($response['callbackFunc'][prop][funcName][0]);
		  						
		  						if(ajaxResponse.objLen($vars)==0){
									if(methodCall != undefined){		  						
		  								funcToCall[methodCall]();
									}
									else{
										funcToCall();
									}
		  						}
		  						else if(ajaxResponse.objLen($vars)==1){
									if(methodCall != undefined){		  						
		  								funcToCall[methodCall]($vars[0]);
									}
									else{
										funcToCall($vars[0]);
									}
		  						}
		  						else if (ajaxResponse.objLen($vars)==2){
		  							if(methodCall != undefined){		  						
		  								funcToCall[methodCall]($vars[0], $vars[1]);
									}
									else{
										funcToCall($vars[0], $vars[1]);
									}		  							
		  						}
		  						else if(ajaxResponse.objLen($vars)==3){
		  							if(methodCall != undefined){		  						
	  									funcToCall($vars[0], $vars[1], $vars[2]);
									}
									else{
										funcToCall($vars[0], $vars[1], $vars[2]);
									}
		  						}
		  						else if(ajaxResponse.objLen($vars)==4){
		  							if(methodCall != undefined){		  						
	  									funcToCall($vars[0], $vars[1], $vars[2], $vars[3]);
									}
									else{
										funcToCall($vars[0], $vars[1], $vars[2], $vars[3]);
									}
		  						}
		  						else if(ajaxResponse.objLen($vars)==5){
		  							if(methodCall != undefined){		  						
	  									funcToCall($vars[0], $vars[1], $vars[2], $vars[3], $vars[4]);
									}
									else{
										funcToCall($vars[0], $vars[1], $vars[2], $vars[3], $vars[4]);
									}
		  						}
		  						else if(ajaxResponse.objLen($vars)==6){
		  							if(methodCall != undefined){		  						
	  									funcToCall($vars[0], $vars[1], $vars[2], $vars[3], $vars[4], $vars[5]);
									}
									else{
										funcToCall($vars[0], $vars[1], $vars[2], $vars[3], $vars[4], $vars[5]);
									}
		  						}
		  						else{
		  							if(ajaxResponse.callbackErrorFunc != null){
		  								window[ajaxResponse.callbackErrorFunc]($vars);
		  							}
		  							else {
		  								if(methodCall != undefined){		  						
		  									funcToCall($vars[0], $vars[1], $vars[2], $vars[3], $vars[4], $vars[5]);
										}
										else{
											funcToCall($vars[0], $vars[1], $vars[2], $vars[3], $vars[4], $vars[5]);
										}
		  							}
		  						}
		  						
		  					}
		  				}
		  				
		  			}
		  			
		  		}
		  	}		  	
		  },
		  error: function ($err){
		  	
		  	$rtn='err text';		  			  	
		  }
		});
		
	},
	objLen : function (obj){
		var pr;
		var $i=0;
		for (pr in obj){
			$i++;
		}
		return $i;
	},
	resetObjKeys : function (obj){
		var rtn = new Array();
		var pr;
		var $i=0;
		
		for (pr in obj){
			rtn[$i]=obj[pr];
			$i++;
		}
		
		return rtn;
	},
	setHTML: function(obj_id, html){
		$('#' + obj_id).html(html);
	},
	redirectOnGetVars: function(field, value){
		var loc = document.location.href;
		if(loc.indexOf('?') == -1){
			document.location.href = loc + '?' + field + '=' + value;
		}		
		else{
			var reg = new RegExp(field + "=[^&]*");
			
			loc = loc.replace(reg, '');
			
			if(loc.substr(-1) != '&'){
				document.location.href = loc + '&' + field + '=' + value;
			}
			else{
				document.location.href = loc + field + '=' + value;
			}
			
		}
	}	
}
